package com.aifast.system.sys.controller;

import com.aifast.common.annotations.AiIdempotent;
import com.aifast.common.base.R;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.system.sys.entity.SysSensitiveWords;
import com.aifast.system.sys.service.SysSensitiveWordsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.io.IOException;
import com.aifast.common.base.Controller;
/**
 * 敏感词数据 控制层
 *
 * @author fujian
 * @date 2022-06-14
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/words")
public class SysSensitiveWordsController extends Controller
{

    private final SysSensitiveWordsService service;

    @GetMapping("list")
    public LayuiDataTable list() {
        return service.list(getSearchValue(), getPage());
    }


//    @LogRecord(type = "敏感词",bizNo = "{{#sysSensitiveWords.id}}",success = "{{#sysSensitiveWords.id==null ? '新增 敏感词数据=》' #sysSensitiveWords.word:'修改' _DIFF#sysSensitiveWords}} ")
    @AiIdempotent
    @PostMapping("add")
    public R add(@Valid SysSensitiveWords sysSensitiveWords) {
        return service.insertOrUpdate(sysSensitiveWords) ? OK() : ERROR();
    }

    @AiIdempotent
    @GetMapping("del")
    public R del() {
        return service.del(getInt("id"), get("ids")) ? OK() : ERROR();
    }

    @GetMapping("info")
    public R info() {
        return service.info(getInt("id"));
    }

    @GetMapping("export")
    public void export() throws IOException {
        service.export(getSearchValue(),response);
    }

}
